﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software component that provide 
// support for localization. This library enable you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace HelloWorld.Startup.ViewModels
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    //LocalizationLibrary References
    using LocalizationLibrary;

    // HelloWorld References
    using HelloWorld.Startup.MVVM;

    /// <summary>
    /// Languages' <see cref="ViewModel"/>.
    /// </summary>
    public class LanguagesVM : ViewModel
     {
        //Fields

        private Language _currentLanguage;

        //Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        public LanguagesVM()
        {
            this.CurrentLanguage = LocalizationManager.CurrentLanguage;
            this.AvailableLanguages = new List<Language>(Languages.AvailableLanguages);
        }

        //Properties

        /// <summary>
        /// Gets available languages.
        /// </summary>
        public IEnumerable<Language> AvailableLanguages { get; private set; }

        /// <summary>
        /// Gets/Sets current language.
        /// </summary>
        public Language CurrentLanguage 
        {
            get 
            {
                return this._currentLanguage;
            }
            set 
            {
                if (this._currentLanguage != value)
                {
                    this._currentLanguage = value;
                    if ((this._currentLanguage != null) &&
                        (!LocalizationManager.CurrentLanguage.Code.Equals(this._currentLanguage.Code)))
                    {
                        LocalizationManager.CurrentLanguage = this.CurrentLanguage;
                    }
                    this.OnPropertyChange("CurrentLanguage");
                }
            }
        }
    }
}